<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2020/2/20
 * Time: 8:36
 */
namespace app\admin\controller;


use think\Db;
use think\Request;
class About extends Base {
    /**
     * 关于我们
     * @return mixed|\think\response\Json
     */
    public function about(){
        if(Request::instance()->isPost()){
            $about_content = input('about_content');
            $res = Db::table('up_about')->where('id', 1)->update(['content' => $about_content]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $about_content = Db::table('up_about')->where('id', 1)->value('content');
        $this->assign('content', $about_content);
        return $this->fetch('about/about');
    }

    /**
     * 联系我们
     * @return mixed|\think\response\Json
     */
    public function phone(){
        if(Request::instance()->isPost()){
            $about_content = input('about_content');
            $res = Db::table('up_about')->where('id', 2)->update(['phone' => $about_content]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $about_content = Db::table('up_about')->where('id', 2)->value('phone');
        $this->assign('content', $about_content);
        return $this->fetch('about/phone');
    }

    /**
     * 隐私协议
     * @return mixed|\think\response\Json
     */

    public function yinsi(){
        if(Request::instance()->isPost()){
            $about_content = input('about_content');
            $zhuce_content = input('zhuce_content');
            $res = Db::table('up_about')->where('id', 3)->update(['content' => $about_content]);
            $res = Db::table('up_about')->where('id', 7)->update(['content' => $zhuce_content]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $about_content = Db::table('up_about')->where('id', 3)->value('content');
        $zhuce_content = Db::table('up_about')->where('id', 7)->value('content');
        $this->assign('content', $about_content);
        $this->assign('content2', $zhuce_content);
        return $this->fetch('about/yinsi');
    }

    /**
     * 派逊天地
     * @return mixed|\think\response\Json
     */

    public function world(){
        if(Request::instance()->isPost()){
            $about_content = input('about_content');
            $res = Db::table('up_about')->where('id', 4)->update(['content' => $about_content]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $about_content = Db::table('up_about')->where('id', 4)->value('content');
        $this->assign('content', $about_content);
        return $this->fetch('about/world');
    }


    /**
     * 平台退货地址
     * @return mixed|\think\response\Json
     */
    public function address(){
        if(Request::instance()->isPost()){
            $about_content = input('about_content');
            $phone = input('phone');
            $res = Db::table('up_about')->where('id', 5)->update(['content' => $about_content,'phone' => $phone]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $about_content = Db::table('up_about')->where('id',5)->find();
        $this->assign('content', $about_content);
        return $this->fetch('about/address');
    }
    /**
     * 尺寸图
     * @return mixed|\think\response\Json
     */
    public function sizepic(){
        if(Request::instance()->isPost()){
            $about_content = input('content');
            $res = Db::table('up_about')->where('id', 6)->update(['content' => $about_content]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $about_content = Db::table('up_about')->where('id',6)->value('content');
        $this->assign('content', $about_content);
        return $this->fetch('about/sizepic');
    }
    /**
     * 运费配置
     * @return mixed|\think\response\Json
     */
    public function postman(){
        if(Request::instance()->isPost()){
            $default_num = input('default_num');
            $default_price = input('default_price');
            $over_price = input('over_price');
            $res = Db::table('up_postman_config')->where('id',1)->update([
                'default_num' => $default_num,
                'default_price' => $default_price,
                'over_price' => $over_price,
            ]);
            if($res){
                return json(['code' => 200, 'msg' => '修改成功']);
            }else{
                return json(['code' => 100, 'msg' => '修改失败或者未做任何修改']);
            }
        }
        $data = Db::table('up_postman_config')->where('id',1)->find();
        $this->assign('data', $data);
        return $this->fetch('about/postman');
    }
    /**
     * 自营商城是否开启
     * @return mixed|\think\response\Json
     */
    public function shopCan(){
        if(Request::instance()->isPost()){
            $status = input('status');
            $phone = input('phone');
            $res = Db::table('up_about')->where('id',8)->update([
                'content' => $status,
                'phone' => $phone
            ]);
            if($res){
                return json(['code' => 200, 'msg' => '修改成功']);
            }else{
                return json(['code' => 100, 'msg' => '修改失败或者未做任何修改']);
            }
        }
        $data = Db::table('up_about')->where('id',8)->find();
        $this->assign('data', $data);
        return $this->fetch('about/shopcan');
    }
    /**
     * 购买后几小时推送给erp
     * @return mixed|\think\response\Json
     */
    public function changesize(){
        if(Request::instance()->isPost()){
            $status = input('content');
            $status = (int)$status;
            if($status < 1){
                return json(['code' => 100, 'msg' => '不能小于1']);
            }
            $res = Db::table('up_about')->where('id',9)->update([
                'content' => $status
            ]);
            if($res){
                return json(['code' => 200, 'msg' => '修改成功']);
            }else{
                return json(['code' => 100, 'msg' => '修改失败或者未做任何修改']);
            }
        }
        $data = Db::table('up_about')->where('id',9)->find();
        $this->assign('data', $data);
        return $this->fetch('about/changesize');
    }
    /**
     * 购买后几小时推送给erp
     * @return mixed|\think\response\Json
     */
    public function donedays(){
        if(Request::instance()->isPost()){
            $status = input('content');
            $status = (int)$status;
            if($status < 1){
                return json(['code' => 100, 'msg' => '不能小于1']);
            }
            $res = Db::table('up_about')->where('id',10)->update([
                'content' => $status
            ]);
            if($res){
                return json(['code' => 200, 'msg' => '修改成功']);
            }else{
                return json(['code' => 100, 'msg' => '修改失败或者未做任何修改']);
            }
        }
        $data = Db::table('up_about')->where('id',10)->find();
        $this->assign('data', $data);
        return $this->fetch('about/donedays');
    }
}